#pragma once

#include "ComponentRealization.h"

#include "Classifier.h"
#include "Component.h"

namespace uml {

ComponentRealization::ComponentRealization(const QString& umlType)
    : Realization(umlType) {}

void ComponentRealization::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Realization::fromJson(json, errorList);
    abstraction_ = JsonSerializable::create<Component>(json.value("abstraction"), errorList);

    JsonSerializable::fromJsonArray(realizingClassifiers_, "realizingClassifiers", json, errorList);
}

void ComponentRealization::toJson(QJsonObject& json) {
    Realization::toJson(json);
    if (abstraction_) {
        QJsonObject abstraction_json;
        abstraction_->toJson(abstraction_json);
        json.insert("abstraction", abstraction_json);
    }
    JsonSerializable::toJsonArray(realizingClassifiers_, "realizingClassifiers", json);
}

/// <summary>
/// abstraction getter
/// The Component that owns this ComponentRealization and which is implemented by
/// its realizing Classifiers.
/// </summary>
shared_ptr<Component> ComponentRealization::abstraction() const {
    return abstraction_;
}

/// <summary>
/// abstraction setter
/// The Component that owns this ComponentRealization and which is implemented by
/// its realizing Classifiers.
/// </summary>
void ComponentRealization::setAbstraction(shared_ptr<Component> value) {
    abstraction_ = value;
}

/// <summary>
/// realizingClassifiers getter
/// The Classifiers that are involved in the implementation of the Component that
/// owns this Realization.
/// </summary>
vector<shared_ptr<Classifier>>& ComponentRealization::realizingClassifiers() {
    return realizingClassifiers_;
}

} // namespace uml
